home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / CC_C / 0696A.ZIP / SHOWENV.C < prev    next >
Text File  |  1987-05-25  |  1KB  |  43 lines

  1. /**
  2. *  showenv -- display the values of any DOS variables named on the 
  3. *             invocation command line
  4. *   from Augie Hanson "Proficient C"
  5. **/
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <spstd.h>
  10.  
  11. main(argc, argv, envp)
  12. int argc;
  13. char **argv;
  14. char **envp;
  15. {
  16.     register char *ep;
  17.     static char pgm[MAXNAME + 1] = { "showenv" };
  18.     extern void getpname(char *, char *);
  19.     /* use an alias if one given to this program */
  20.     if (_osmajor >= 3)
  21.         getpname(*argv, pgm);
  22. /* if no arguments  show the full environment list */
  23.     if (argc==1)
  24.         for(; *envp; ++ envp)
  25.             printf("%s\n", *envp);
  26.     else {
  27. /*
  28. * treat all args as DOS variable names and display values of
  29. * only specified variables
  30. */
  31.         ++argv; /* skip past command name */
  32.         --argc;
  33.         while (argc > 0) {
  34.           if ((ep = getenv(strupr(*argv))) == NULL)
  35.             fprintf(stderr, "%s not defined\n", *argv);
  36.           else
  37.             printf("%s=%s\n", *argv, ep);
  38.           ++argv;
  39.           --argc;
  40.            }
  41.     }
  42.     exit(0);
  43. }